package com.cqc.zhbjcqc.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cqc.zhbjcqc.R;

import java.util.List;

/**
 * Created by cui on 2016/9/27.
 */

public class LeftMenuAdapter extends ListViewBaseAdapter<String> {

    private int currentItemPosition = 0;
    public LeftMenuAdapter(Context context, List<String> list) {
        super(context, list);
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_menu, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tv_menu.setText(list.get(i));
        if (currentItemPosition == i){
            holder.iv_menu.setBackgroundResource(R.mipmap.menu_arr_select);
            holder.tv_menu.setTextColor(Color.RED);
            convertView.setBackgroundResource(R.mipmap.menu_item_bg_select);
        } else {
            holder.iv_menu.setBackgroundResource(R.mipmap.menu_arr_normal);
            holder.tv_menu.setTextColor(Color.WHITE);
            convertView.setBackgroundResource(android.R.color.transparent);
        }

        return convertView;
    }

    public void setCurrentItemPosition(int i) {
        this.currentItemPosition = i;
    }

    public class ViewHolder {

        public ImageView iv_menu;
        public TextView tv_menu;

        public ViewHolder(View convertView) {
            super();
            iv_menu = (ImageView) convertView.findViewById(R.id.iv_menu);
            tv_menu = (TextView) convertView.findViewById(R.id.tv_menu);
        }
    }
}
